package com.api.regression.group.getgroupsbyid;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.GroupApi;
import com.zyncro.api.model.GroupApiType;
import com.zyncro.api.model.GroupFilterApiType;
import com.zyncro.api.model.GroupOrderFieldFilterApiType;
import com.zyncro.api.model.OrderFilterApiType;
import com.zyncro.api.model.PagedItemsResultApi;

@ContextConfiguration(locations = { "classpath:/group/group-context.xml" })
public class GetGroupsById extends AbstractApiTest {

	@Value("#{staticgroups['user.getGroups'].appId}")
	private String userUrn;

	@Value("#{staticgroups['user.getGroups'].password}")
	private String userPassword;

	@Value("#{staticgroups['cant.groups.all']}")
	private int cantAllGroups;

	@Value("#{staticgroups['cant.groups.tag']}")
	private int cantTagGroups;

	@Value("#{staticgroups['cant.groups.department']}")
	private int cantDepartmentGroups;

	@Value("#{staticgroups['cant.groups.member']}")
	private int cantMemberGroups;

	@Value("#{staticgroups['cant.groups.notMember']}")
	private int cantNotMemberGroups;

	@BeforeClass
	protected void loginUser() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test
	public void testGetAllGroups() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		List<GroupApiType> groupTypes = null;
		GroupFilterApiType groupFilter = GroupFilterApiType.ALL;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), cantAllGroups, "Total group items");
	}

	@Test
	public void testGetCompanyFeedGroup() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = new ArrayList<GroupApiType>();
		groupTypes.add(GroupApiType.COMPANY_FEED);

		GroupFilterApiType groupFilter = null;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), 1, "Total companyFeed group items");
	}

	@Test
	public void testGetPersonalFeedGroup() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = new ArrayList<GroupApiType>();
		groupTypes.add(GroupApiType.PERSONAL_FEED);

		GroupFilterApiType groupFilter = null;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), 1, "Total personalFeed group items");
	}

	@Test
	public void testGetTagGroups() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = new ArrayList<GroupApiType>();
		groupTypes.add(GroupApiType.TAG);

		GroupFilterApiType groupFilter = GroupFilterApiType.ALL;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), cantTagGroups, "Total tag group items");
	}

	@Test
	public void testGetPersonalGroup() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = new ArrayList<GroupApiType>();
		groupTypes.add(GroupApiType.PERSONAL);

		GroupFilterApiType groupFilter = null;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), 1, "Total personal group items");
	}

	@Test
	public void testGetDepartmentGroups() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = new ArrayList<GroupApiType>();
		groupTypes.add(GroupApiType.DEPARTMENT);

		GroupFilterApiType groupFilter = GroupFilterApiType.ALL;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), cantDepartmentGroups, "Total department group items");
	}

	@Test
	public void testGetGroupsWhereMember() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = null;

		GroupFilterApiType groupFilter = GroupFilterApiType.JUST_MEMBER;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), cantMemberGroups, "Total member group items");
	}

	@Test
	public void testGetGroupsWhereNotMember() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		List<GroupApiType> groupTypes = null;

		GroupFilterApiType groupFilter = GroupFilterApiType.NOT_MEMBER;

		String startsWith = null;
		GroupOrderFieldFilterApiType orderFilterField = null;
		OrderFilterApiType orderFilterType = null;

		PagedItemsResultApi<GroupApi> result = getApi().getService(IGroupApiService.class).getGroups(pageNumber, itemsPerPage, groupTypes,
				groupFilter, startsWith, orderFilterField, orderFilterType);

		Assert.assertEquals(result.getTotalItems(), cantNotMemberGroups, "Total not member group items");
	}
}
